/**
* \file Thread.cpp
* \brief Thread declaration class
* \author Edouard ROGE
* \date 29 august 2012
*/

#include "Core/Log/LogManager.h"
#include "Core/Profile/CodeProfile.h"
#include "ThreadManager.h"
#include "Thread.h"

namespace Core
{
	namespace Thread
	{
		Thread::Thread()
		{

		}

		Thread::~Thread()
		{
		}

		void Thread::Start()
		{
			ThreadManager::GetInstance().Register(this);
		}

		std::thread::id Thread::GetThreadId() const
		{
			return std::this_thread::get_id();
		}

		void Thread::Synchronize()
		{
			m_handle.join();
		}

		void Thread::RunThread()
		{
			PROFILEEX("New thread", m_parentThread);
			m_threadId = GetThreadId();
			LOG_INFO("Start thread %d", m_threadId);
			Run();
			LOG_INFO("End thread %d", m_threadId);
			ThreadManager::GetInstance().Unregister(this);
		}
	}
}
